﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Lottery.MediaData.Core {
    /// <summary>
    /// 数差， 表二 使用
    /// </summary>
    public class SC {
        /// <summary>
        /// 大差
        /// </summary>
        public string D { get; set; }

        /// <summary>
        /// 中差
        /// </summary>
        public string Z { get; set; }

        /// <summary>
        /// 小差
        /// </summary>
        public string X { get; set; }

        /// <summary>
        /// 3
        /// </summary>
        public int Three { get; set; }

        /// <summary>
        /// 1
        /// </summary>
        public int One { get; set; }

        /// <summary>
        /// 0
        /// </summary>
        public int Zero { get; set; }

        /// <summary>
        /// 预测奖号
        /// </summary>
        public string PreNumber { get; set; }

        /// <summary>
        /// 获得大数对应的310
        /// </summary>
        /// <returns></returns>
        public string GetDaShu310() {
            var data = new Dictionary<string, int>();
            data.Add("3", Three);
            data.Add("1", One);
            data.Add("0", Zero);

            var d = from item in data
                    orderby item.Value descending
                    select item;

            var sb = new StringBuilder();

            sb.Append(d.ElementAt(0).Key);

            if (d.ElementAt(0).Value == d.ElementAt(1).Value) {
                sb.Append(d.ElementAt(1).Key);
            }

            if (d.ElementAt(0).Value == d.ElementAt(2).Value) {
                sb.Append(d.ElementAt(2).Key);
            }

            return sb.ToString();
        }

        /// <summary>
        /// 获得中数的310
        /// </summary>
        /// <returns></returns>
        public string GetZhongShu310() {
            var data = new Dictionary<string, int>();
            data.Add("3", Three);
            data.Add("1", One);
            data.Add("0", Zero);

            var d = from item in data
                    orderby item.Value descending
                    select item;

            var sb = new StringBuilder();

            if (Three == One && Three == Zero) {
                return string.Empty;
            }

            if (d.ElementAt(0).Value != d.ElementAt(1).Value) {
                sb.Append(d.ElementAt(1).Key);
                if (d.ElementAt(1).Value == d.ElementAt(2).Value) {
                    sb.Append(d.ElementAt(2).Key);
                }
            } else {
                sb.Append(d.ElementAt(2).Key);
            }

            return sb.ToString();
        }

        /// <summary>
        /// 获得小数对应的310
        /// </summary>
        /// <returns></returns>
        public string GetXiaoShu310() {
            var data = new Dictionary<string, int>();
            data.Add("3", Three);
            data.Add("1", One);
            data.Add("0", Zero);

            var d = from item in data
                    orderby item.Value descending
                    select item;

            var sb = new StringBuilder();

            if (Three == One && Three == Zero) {
                return string.Empty;
            }

            if (d.ElementAt(0).Value != d.ElementAt(1).Value) {
                if (d.ElementAt(1).Value != d.ElementAt(2).Value) {
                    sb.Append(d.ElementAt(2).Key);
                } else {
                    sb.Append(d.ElementAt(1).Key);
                    sb.Append(d.ElementAt(2).Key);
                }
            } else {
                sb.Append(string.Empty);
            }

            return sb.ToString();
        }

        public void CalcDZX() {
            // 310的媒体统计数据相同的时候，本次就无效
            if (Three == One && One == Zero) {
                D = Z = X = string.Empty;
                return;
            }

            var data = new int[] { Three, One, Zero };
            var list = (from item in data
                        orderby item descending
                        select item).ToArray();
            if (list[1] == list[2]) {
                D = X = string.Empty;
                Z = (list[0] - list[1]).ToString();
                return;
            } else if (list[0] == list[1]) {
                D = X = string.Empty;
                Z = (list[1] - list[2]).ToString();
                return;
            }

            var d = list[0] - list[2];
            var z = list[0] - list[1];
            var x = list[1] - list[2];
            D = d.ToString();
            Z = z.ToString();
            X = x.ToString();
        }

    }
}
